// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router' //引入路由模块


import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' //引入公共的样式

import store from '@/store/store' //引入Vuex模块


Vue.use(ElementUI)
Vue.config.productionTip = false

// Vue.config.keyCodes.enter = 13 //自定义全局键盘码



//全局守卫
router.beforeEach((to, from, next) => {
    let token = localStorage.getItem('mytoken')
        //如果登录过,继续访问
    if (token) {
        next()
    } else { //如果没登录,访问其他页面则跳到登录页面
        if (to.path !== '/login') {
            next({ path: '/login' })
        } else {
            next()
        }
    }
})




/* eslint-disable no-new */
new Vue({
    el: '#app',
    router, //注入路由
    store, //注入vuex实例对象
    components: { App },
    template: '<App/>'
})